cmake_minimum_required(VERSION 3.25)
project(MyProject CXX C)

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Include directories
include_directories(libs)

# 为 sqlite3 库明确指定 C 语言
set_source_files_properties(libs/sqlite3.c PROPERTIES LANGUAGE C)
add_library(sqlite3 STATIC libs/sqlite3.c)

# Source files
set(SOURCES
    src/main.cpp
)

# 根据平台添加特定的源文件和定义
if(WIN32)
    list(APPEND SOURCES src/windows/iocp_server.cpp)
    add_definitions(-DPLATFORM_WINDOWS)
elseif(APPLE)
    list(APPEND SOURCES src/mac/kqueue_server.cpp)
    add_definitions(-DPLATFORM_MAC)
elseif(UNIX)
    list(APPEND SOURCES src/linux/io_uring_server.cpp)
    add_definitions(-DPLATFORM_LINUX)
endif()

# Add executable target
add_executable(my_program ${SOURCES})
target_link_libraries(my_program PRIVATE sqlite3)

# 链接必要的库
if(WIN32)
    target_link_libraries(my_program PRIVATE ws2_32)
endif()

# 添加调试器支持
set(CMAKE_BUILD_TYPE Debug)

# Compiler flags
if(MSVC)
    target_compile_options(my_program PRIVATE /W4)
else()
    target_compile_options(my_program PRIVATE -Wall -Wextra -Wpedantic)
endif()